package com.ctgu.springstart.controller;

import com.ctgu.springstart.domain.JsonData;
import com.ctgu.springstart.service.ProducerService;
import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.jms.Destination;

@RestController
@RequestMapping("/api/activemq")
public class ActiveMQController {

    @Autowired
    private ProducerService producerService;

    @GetMapping("order")
    public Object order(String msg){
        Destination destination = new ActiveMQQueue("order.queue");
        producerService.sendMessage(destination, msg);
        return JsonData.builder().msg("activeMQ order success").build();
    }

    @GetMapping("common")
    public Object common(String msg){
        producerService.sendMessage(msg);
        return JsonData.builder().msg("activeMQ common success").build();
    }

    @GetMapping("topic")
    public Object topic(String msg){
        producerService.publish(msg);
        return JsonData.builder().msg("activeMQ topic success").build();
    }

}
